{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "from sympy import *\n",
    "from sympy.abc import *\n",
    "from sympy import sin, cos, pi\n",
    "import numpy as np\n",
    "from IPython.display import display, Math\n",
    "from handcalcs import *\n",
    "from sympy.physics.hydrogen import*\n",
    "f,g,T,V,T= symbols('f g x v t', cls=Function)\n",
    "w_0,w_1,w_2,v_0,v_1,J_0,J_1,J_A,J_B,m_1,m_2,J_2,w,phi= symbols('w_0 w_1 w_2 v_0 v_1,J_0,J_1,J_A,J_B,m_1,m_2,J_2,omega,varphi')\n",
    "beta=symbols('beta')\n",
    "def out(x,x_1=0,x_2=0,x_3=0,x_4=0,x_5=0,x_6=0,x_7=0,x_8=0,x_9=0,x_10=0,x_11=0):\n",
    "   if x==0:\n",
    "      return\n",
    "   if x_1==0:\n",
    "       display(Math(latex(x)))\n",
    "   else:\n",
    "       if type(x_1)==str:\n",
    "          display(Math(x_1+latex(x)))\n",
    "       else:\n",
    "           display(Math(latex(x)))\n",
    "   out(x_2,x_3)\n",
    "   out(x_4,x_5)\n",
    "   out(x_6,x_7)\n",
    "   out(x_8,x_9)\n",
    "   out(x_10,x_11)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$$a=\\frac{F}{m}=-\\frac{k}{m}x=-w^2x$$\n",
    "> + 注意`向量圆(旋转矢量)`的使用\n",
    "\n",
    "> + $\\upsilon$是频率$\\upsilon=1/T$ \n",
    "\n",
    "> + 初相位本来是$[0,\\pi]$，但是通常把大于$\\pi$的记作`负值`\n",
    "\n",
    "> +"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/latex": [
       "$\\displaystyle X=A \\cos{\\left(\\omega t + \\varphi \\right)}$"
      ],
      "text/plain": [
       "<IPython.core.display.Math object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/latex": [
       "$\\displaystyle V=- A \\omega \\sin{\\left(\\omega t + \\varphi \\right)}$"
      ],
      "text/plain": [
       "<IPython.core.display.Math object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/latex": [
       "$\\displaystyle T=- A \\omega^{2} \\cos{\\left(\\omega t + \\varphi \\right)}$"
      ],
      "text/plain": [
       "<IPython.core.display.Math object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "X=A*cos(w*t+phi)\n",
    "V=X.diff(t)\n",
    "aa=V.diff(t)\n",
    "out(X,'X=',V,'V=',aa,'T=')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##### `单摆和复摆`\n",
    "$$w=\\sqrt{\\frac{mgl}{J}}=\\sqrt{\\frac{g}{l}}$$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##### `简谐振动的能量`\n",
    "$$E_k=\\frac{1}{2}mv^2=\\frac{A^{2} m \\omega^{2} \\sin^{2}{\\left(\\omega t + \\varphi \\right)}}{2}$$"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/latex": [
       "$\\displaystyle \\frac{32 a^{4}}{15}$"
      ],
      "text/plain": [
       "32*a**4/15"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "x=r*cos(theta)*sin(phi)\n",
    "y=r*sin(theta)*sin(phi)\n",
    "z=cos(phi)\n",
    "args = Matrix([phi,theta])\n",
    "ans1=Matrix([y,z]).jacobian(args).det()\n",
    "ans2=Matrix([z,x]).jacobian(args).det()\n",
    "ans3=Matrix([x,y]).jacobian(args).det()\n",
    "#out(trigsimp(ans3))\n",
    "#out((sqrt(trigsimp(trigsimp(ans1**2)+trigsimp(ans2**2)+trigsimp(ans3**2)))))\n",
    "#integrate((x+y+z)*sqrt((ans1**2)+(ans2**2)+(ans3**2)),(phi,0,pi/2),(theta,0,2*pi))\n",
    "integrate(r**3*cos(theta),(r,0,2*a*cos(theta)),(theta,0,pi/2))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/latex": [
       "$\\displaystyle \\frac{\\pi r^{4} \\sqrt{R^{2} - r^{2}}}{4}$"
      ],
      "text/plain": [
       "pi*r**4*sqrt(R**2 - r**2)/4"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "integrate(r**4*sqrt(R**2-r**2)*cos(theta)**2*sin(theta)**2,(theta,0,2*pi))"
   ]
  }
 ],
 "metadata": {
  "interpreter": {
   "hash": "05a237592cd1f1c47d6da52b1c9e9cb4b6d7e67883224033955e685c2762c5fd"
  },
  "kernelspec": {
   "display_name": "Python 3.9.10 64-bit (windows store)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.7"
  },
  "orig_nbformat": 4
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
